'use strict';
const Service = require('egg').Service;

class AcgImgService extends Service {
    async acgImg(res) {
        // 请求数据
        let sendMsg = this.ctx.service.sendMsg;  
        let result = await this.ctx.curl('https://api.lolicon.app/setu/?r18=2&apikey=885915936065db81372f56&size1200=true', {
            contentType: 'json'
        });
        /*格式：
        {
            API_name: 'QAC_API',
            imgurl: '',
            width: '',
            height: ''
        }    
        */
        result = JSON.parse(result.data.toString());
        console.log(result);
        if (res.message_type == 'group') {
            sendMsg.sendToGroup({
                id:res.group_id,
                msg:`[CQ:image,file=${result.data[0].url}]`
            })
            // console.log('qun');
        }else{
            sendMsg.sendToPerson({
                id:res.user_id,
                msg:`[CQ:image,file=${result.data[0].url}]`
            })
        }
    }

    async badWomanImg(res) {
        let sendMsg = this.ctx.service.sendMsg;
        let result = await this.ctx.curl('https://api.lolicon.app/setu/?r18=1&apikey=885915936065db81372f56&size1200=true', {
            contentType: 'json'
        });
        // console.log(result.data.toString());
        result = JSON.parse(result.data.toString());
        // console.log(result)
        if (res.message_type == 'group') {
            sendMsg.sendToGroup({
                id:res.group_id,
                msg:`[CQ:image,file=${result.data[0].url}]`
            })
        }else{
            sendMsg.sendToPerson({
                id:res.user_id,
                msg:`[CQ:image,file=${result.data[0].url}]`
            })
        }
    }
}

module.exports = AcgImgService;